/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package times;

import java.util.Collection;
import java.util.List;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import times.persistence.controllers.AnimalSpeciesJpaController;
import times.persistence.controllers.CategoryClassJpaController;
import times.persistence.controllers.CategoryJpaController;
import times.persistence.controllers.PriceSourceJpaController;
import times.persistence.controllers.SlaughterPropertyJpaController;
import times.persistence.controllers.PriceSourceSlaughterHeaderJpaController;
import times.persistence.controllers.PropertyPriceSourceJpaController;
import times.persistence.controllers.PriceSlaughterLambJpaController;
import times.persistence.controllers.ForeasJpaController;
import times.persistence.entities.AnimalSpecies;
import times.persistence.entities.CategoryClass;
import times.persistence.entities.PriceSlaughter;
import times.persistence.entities.SlaughterProperty;
import times.persistence.entities.PriceSource;
import times.persistence.entities.PriceSourceSlaughterHeader;
import times.persistence.controllers.PriceSlaughterJpaController;
import times.persistence.controllers.exceptions.NonexistentEntityException;
import times.persistence.entities.Category;
import times.persistence.entities.PropertyPriceSource;
import times.persistence.entities.PriceSlaughterLamb;
import times.persistence.entities.Foreas;
/**
 *
 * @author Administrator
 */
public class TimesDAO {

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("TimesJPAPU");
    PriceSourceJpaController psjc = new PriceSourceJpaController(emf);
    AnimalSpeciesJpaController asjc = new AnimalSpeciesJpaController(emf);
    PriceSourceSlaughterHeaderJpaController psshjc = new PriceSourceSlaughterHeaderJpaController(emf);
    PriceSlaughterJpaController psljc = new PriceSlaughterJpaController(emf);
    CategoryClassJpaController ccljc = new CategoryClassJpaController(emf);
    CategoryJpaController cjc = new CategoryJpaController(emf);
    SlaughterPropertyJpaController spjc = new SlaughterPropertyJpaController(emf);
    PropertyPriceSourceJpaController ppsjc = new PropertyPriceSourceJpaController(emf);
    PriceSlaughterLambJpaController pslljc = new PriceSlaughterLambJpaController(emf);
    ForeasJpaController fjc = new ForeasJpaController(emf);

    private String qryFindPriceSourceByName;

    public List<PriceSource> findPriceSourceEntities() {

        return psjc.findPriceSourceEntities();

    }

    public PriceSource findPriceSourceById(Integer id) {
        return psjc.findPriceSource(id);
    }

    public List<PriceSource> findPriceSourceByName(String name) {
        return psjc.getEntityManager()
                .createNamedQuery(qryFindPriceSourceByName)
                .setParameter("name", "%" + name + "%")
                .getResultList();

    }

    public void createPriceSource(PriceSource priceSource) {
        psjc.create(priceSource);
    }

    public void editPriceSource(PriceSource priceSource) throws Exception {
        psjc.edit(priceSource);
    }

    public List<AnimalSpecies> findAnimalSpeciesEntities() {
        return asjc.findAnimalSpeciesEntities();

    }

    public void createPriceSourceSlaughterHeader(PriceSourceSlaughterHeader priceSourceSlaughterHeader) {
        psshjc.create(priceSourceSlaughterHeader);
    }

    public void editPriceSourceSlaughterHeader(PriceSourceSlaughterHeader priceSourceSlaughterHeader) throws Exception {
        psshjc.edit(priceSourceSlaughterHeader);
    }

    public List<PriceSourceSlaughterHeader> findPriceSourceSlaughterHeaderEntities() {
        return psshjc.findPriceSourceSlaughterHeaderEntities();

    }

    public List<CategoryClass> findCategoryClassEntities() {

        return ccljc.findCategoryClassEntities();

    }

    public List<PriceSlaughter> findPriceSlaughterEntities() {
        return psljc.findPriceSlaughterEntities();

    }

    public void createPriceSlaughter(PriceSlaughter priceSlaughter) {
        psljc.create(priceSlaughter);
    }

    public void editPriceSlaughter(PriceSlaughter priceSlaughter) throws Exception {
        psljc.edit(priceSlaughter);
    }

    public void createCategory(Category category) {
        cjc.create(category);
    }

    public void editCategory(Category category) throws Exception {
        cjc.edit(category);
    }

    public List<Category> findCategoryEntities() {

        return cjc.findCategoryEntities();

    }

    public void createSlaughterProperty(SlaughterProperty slaughterProperty) {
        spjc.create(slaughterProperty);
    }

    public void editSlaughterProperty(SlaughterProperty slaughterProperty) throws Exception {
        spjc.edit(slaughterProperty);
    }

    public List<PropertyPriceSource> findPropertyPriceSourceEntities() {

        return ppsjc.findPropertyPriceSourceEntities();

    }

    public void deleteSlaughterProperty(Integer slaughterPropertyId) throws NonexistentEntityException {
        
        spjc.destroy(slaughterPropertyId);
    }

    public void deletePriceSlaughter(Integer priceSlaughterId) throws NonexistentEntityException {
    
         psljc.destroy(priceSlaughterId);
    }

    public List<PriceSlaughterLamb> findPriceSlaughterLambEntities() {

        return pslljc.findPriceSlaughterLambEntities();

    }

    
        public void deletePriceSlaughterLamb(Integer priceSlaughterLambId) throws NonexistentEntityException {
    
         pslljc.destroy(priceSlaughterLambId);
    }
        
        public void editPriceSlaughterLamb(PriceSlaughterLamb priceSlaughterLamb) throws Exception {
        pslljc.edit(priceSlaughterLamb);
    }
          public void createPriceSlaughterLamb(PriceSlaughterLamb priceSlaughterLamb) {
          pslljc.create(priceSlaughterLamb);
    }

        public List<Foreas> findForeasEntities() {

        return fjc.findForeasEntities();
        

    }
        
        
        public PriceSourceSlaughterHeader findPriceSourceSlaughterHeaderById(Integer id){
            return psshjc.findPriceSourceSlaughterHeader(id);
        }

    public AnimalSpecies findAnimalSpeciesById(Integer id) {
        return asjc.findAnimalSpecies(id);
    }
    
    
    
}
